package org.ljy.lotterysystem.dao.mapper;

import org.apache.ibatis.annotations.*;
import org.ljy.lotterysystem.dao.dataobject.PrizeDO;

import java.util.List;

@Mapper
public interface PrizeMapper {

    @Insert("insert into prize (name,description,price,image_url)" +
            " values (#{name},#{description},#{price},#{imageUrl})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    int insert(PrizeDO prizeDO);

    /**
     * 查询奖品总数
     * @return
     */
    @Select("select count(1) from prize")
    int count();

    /**
     *  获取奖品列表
     * @param offset 偏移量
     * @param pageSize 查询的个数
     * @return 奖品列表
     */
    @Select("select * from prize order by id desc limit #{offset},#{pageSize}")
    List<PrizeDO> selectPrizeList(@Param("offset") Integer offset, @Param("pageSize")Integer pageSize);

    @Select("<script> " +
            "select id from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Long> selectExistByIds(@Param("items") List<Long> prizeIds);

    @Select("<script>" +
            " select * from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<PrizeDO> batchSelectByIds(@Param("items") List<Long> prizeIds);

    @Select("select * from prize where id = #{prizeId}")
    PrizeDO selectById(@Param("prizeId")Long prizeId);
}
